package cn.com.controller;

import cn.com.beans.CollegeInfo;
import cn.com.service.CollegeInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/rank")
public class RankController {
    @Resource
    private CollegeInfoService collegeInfoService;

    @GetMapping
    public String getSchoolRank(Integer page,CollegeInfo collegeInfo, ModelMap model,String prid,String category,String level,String features,String type){
        if(prid != null){
            collegeInfo.setCoPrid(prid);
        }
        if(category != null){
            collegeInfo.setCoCategory(category);
        }
        if(level != null){
            collegeInfo.setCoLevel(level);
        }
        if(features != null){
            collegeInfo.setCoFeatures(features);
        }
        if(type != null){
            collegeInfo.setCoType(type);
        }
        if(page == null){
            page = 1;
        }
        List<CollegeInfo> all = this.collegeInfoService.findAll(collegeInfo);
        Integer sum = this.collegeInfoService.findRownum(collegeInfo);
        model.addAttribute("rank",all);
        model.addAttribute("cpage",page);
        model.addAttribute("prid",prid);
        model.addAttribute("category",category);
        model.addAttribute("level",level);
        model.addAttribute("features",features);
        model.addAttribute("type",type);
        model.addAttribute("sum",sum);
        return  "select/schoolrank";
    }
}
